<?
#####################################################
#  COPYRIGHT NOTICE
#####################################################
# In the following statements, the term "this 
# program" refers to all files associated with the
# execution and distribution of Adtrackz.
#
# This Program is Copyright 2004 Jonah Klimack.
# All Rights Reserved. 
#
# Selling the code for this program, modifying 
# and/or redistributing the code for this program
# in part or in whole over the Internet or in any 
# other medium is expressly forbidden. Violators
# will be prosecuted to the fullest extent of the law
# Copyright and header information may not be
# modified.
#
# This program is distributed "as is" and without 
# warranty of any kind, either express or implied.
# In no event shall the liability of Jonah Klimack 
# for any damages, losses and/or causes of 
# action exceed the total amount paid by the 
# user for this software.		
#####################################################
# DO NOT MODIFY ANYTHING IN THIS FILE
#####################################################



require "header.php";

?>
<p class="small" align="left">
Keywords > Generate Tracking Urls
</p>
<p class="heading">
Generate Tracking Urls
</p>
<p>
Enter a list of keywords and Adtrackz will generate a list of tracking urls for you to submit to any pay per click search engine. </p><p>
<a href="http://adtrackz.com/support/manual/help.keywords.php" target=_manual>Click here</a> for some background information on tracking keywords, and then <a href="http://adtrackz.com/support/manual/help.masskeyword.php" target=_manual>click here</a> for instructions on using this feature.
<br><br>
<?


if ($submit)
{
	if (!$inputdata)
		error("You didn't enter any keywords.");

	$campaign_adcode = mysql_fetch_row(mysql_query("select adcode from adtrackz_campaigns where ID='$campaign'"));
	$lines = explode("\n", $inputdata);
	$c=0;
	foreach ($lines as $line)
	{
		list($keyword, $bid, $url) = explode("|", $line);	
		//trim it up
		$keyword = trim($keyword);
		$bid = trim($bid);
		$url = trim($url);
		
		//if google, preserve spaces for keyword ** bid ** url
		if ($google)
			$gkeyword = stripslashes($keyword);

		//replace spaces with underline for tracking urls
		$keyword = str_replace(" ", "_", $keyword);
		$keyword = stripslashes($keyword);

		if ($bid && !preg_match("/\b\d+\b/", $bid))
		{
			error("Cost must be in numerical format.");
			require "footer.php";
			exit;
		}
		elseif ($url && !preg_match("/(http|https):\/\//", $url))
		{
			error("$url is not a valid url.");
			require "footer.php";
			exit;
		}
		/*
		elseif (preg_match("/(\W+|\s+)/", $keyword, $matches))
		{
			error("Keyword must contain letters,digits, spaces or an underscore character only.");
			require "footer.php";
			exit;
		}
		*/
		else //BUILD OUTPUT
		{

			if ($www)
				$domain = str_replace("www.", "", $domain);

			if ($root)
				$directory = "";
			else
				$directory = $udirectory."/";

			if (!$google) //output keyword liskt in google format
			{
				if ($keyword && $bid && $url)
				{
					$output[$c] =  "http://".$domain."/".$directory."go.php?c=".$campaign_adcode[0]."&s=".$keyword."&cpc=".$bid."&u=".$url;
					$c++;
				}
				elseif ($keyword && $bid)
				{
					$output[$c] = "http://".$domain."/".$directory."go.php?c=".$campaign_adcode[0]."&s=".$keyword."&cpc=".$bid;
					$c++;
				}
				elseif ($keyword && $url)
				{
					$output[$c] = "http://".$domain."/".$directory."go.php?c=".$campaign_adcode[0]."&s=".$keyword."&u=".$url;
					$c++;
				}
				elseif ($keyword)
				{
					$output[$c] = "http://".$domain."/".$directory."go.php?c=".$campaign_adcode[0]."&s=".$keyword;
					$c++;
				}

			}
			else //GOOGLE

			{
				if ($keyword && $bid && $url)
				{
					$bid2 = $bid / 100;
					$output[$c] =  "$gkeyword ** $bid2 ** http://".$domain."/".$directory."go.php?c=".$campaign_adcode[0]."&s=".$keyword."&cpc=".$bid."&u=".$url;
					$c++;
				}
				elseif ($keyword && $bid)
				{
					//have to use default url
					$bid2 = $bid / 100;
					$output[$c] = "$gkeyword ** $bid2 **  http://".$domain."/".$directory."go.php?c=".$campaign_adcode[0]."&s=".$keyword."&cpc=".$bid;
					$c++;
				}
				elseif ($keyword && $url)
				{
					$output[$c] = "$gkeyword **  http://".$domain."/".$directory."go.php?c=".$campaign_adcode[0]."&s=".$keyword."&u=".$url;
					$c++;
				}
				elseif ($keyword)
				{
					$output[$c] = "$gkeyword ** http://".$domain."/".$directory."go.php?c=".$campaign_adcode[0]."&s=".$keyword;
					$c++;
				}
			}
		}
	}

	//create a string to put it in text area
	$string = "<textarea rows=20 cols=60>";
	foreach($output as $item)
		$string .= $item."\n";
	$string .= "</textarea>";

	//PRINT OUTPUT
	alert("Here are your tracking urls. <br><br> $string");
}
?>

<form action=keywords.php method=post>
<table width="600" border="0" cellspacing="0" cellpadding="5" align="center" bgcolor="white"  bordercolor="white">
<tr>
	<td>Campaign</td>
	<td>
	<select name="campaign">
	<?
	$ppc_campaigns = mysql_query("select * from adtrackz_campaigns where ppc=1 order by adcode asc");
	while($ppc_campaign = mysql_fetch_row($ppc_campaigns))
		echo "<option value=\"$ppc_campaign[0]\" selected>$ppc_campaign[2]</option>";
	?>
	</select>
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td><span class=small>
	Choose the campaign that you would like the keywords to go under. Only pay per click campaigns will show up in this list.
	</span>
	</td>
</tr>
<tr>
	<td valign="top">Google Tracking Urls</td>
	<td valign="top"><input type=checkbox name=google></td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td><span class=small>
	Click this if you want to generate tracking urls that you can mass import into google.
	</span>
	</td>
</tr>

<tr>
	<td valign="top">Shorten Url: Root</td>
	<td valign="top"><input type=checkbox name=root></td>
</tr>

<tr>
	<td>&nbsp;</td>
	<td><span class=small>
	Use yourdomain.com/go.php instead of yourdomain.com/adtrackz/go.php. This will only work if you opted to move go.php in your root directory during installation.
	</span>
	</td>
</tr>
<tr>
	<td valign="top">Shorten Url: WWW</td>
	<td valign="top"><input type=checkbox name=www></td>
</tr>

<tr>
	<td>&nbsp;</td>
	<td><span class=small>
	Take out the www. in the tracking url to make it shorter. Use this only if your domain works when you access it without the www.
	</span>
	</td>
</tr>
<tr>
	<td valign=top colspan=2>Enter your keyword list</td>
</tr>
<tr>
	<td colspan=2><textarea name=inputdata rows=10 cols=65></textarea></td>
</tr>
<tr>
	<td colspan=2>&nbsp;</td>
</tr>
<tr>
	<td colspan=2 align=center><input type=submit name=submit value="Generate Tracking Urls"></td>
</tr>
</table>
</form>

<?

require "footer.php";

?>